import { defineStore } from 'pinia';
const useGlobalStore = defineStore('global', {
	state() {
		return {
			wxOpenId: '',
			aliOpenId: '',
			servicePhone:"",
			payAmount: ""   // 用户支付金额
		};
	},
	getters: {
		getWxOpenId(state: any) {
			if (!state.wxOpenId) {
				const wxOpenId = uni.getStorageSync('wxOpenId');
				state.wxOpenId = wxOpenId;
			}
			return state.wxOpenId;
		},
		getAliOpenId(state: any) {
			if (!state.aliOpenId) {
				const aliOpenId = uni.getStorageSync('aliOpenId');
				state.aliOpenId = aliOpenId;
			}
			return state.aliOpenId;
		},
		getServicePhone(state: any) {
			if (!state.servicePhone) {
				const phone = uni.getStorageSync('servicePhone');
				state.servicePhone = phone;
			}
			return state.servicePhone;
		}
	},
	actions: {
		setWxOpenId(openId: string) {
			this.wxOpenId = openId;
			uni.setStorageSync('wxOpenId', openId);
		},
		setAliOpenId(openId: string) {
			this.aliOpenId = openId;
			uni.setStorageSync('aliOpenId', openId);
		},
		setServicePhone(phone:string) {
			this.servicePhone = phone
			uni.setStorageSync('servicePhone', phone);
		}
	}
});

export default useGlobalStore;
